

ext='so'
sysname=$(shell uname -s); 



all: share_lib testcb
	@echo $(sysname)


share_lib: libtestcallback.dll

#common flags
CC=gcc
SYSLIBS=
LDFLAGS=$(SYSLIBS) 

#-Wl,-Bstatic -lstdc++ -lgcc_eh -lpthread -Wl,-Bdynamic
#-static-libstdc++ -static-libgcc -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive -Wl,-Bdynamic
CPP_COMMON=../cpp_common
INCLUDES=-I$(CPP_COMMON) -I./ -I../cpp_win
CFLAGS=$(SYSCFLAGS) $(INCLUDES)
SYS_CFLAGS=-Wall -pedantic -g -O2 -D__WINDOWS__





#for openssl & tassl
OPENSSL_DIR=$(TASSL)
OPENSSL_INCLUDES=-I$(OPENSSL_DIR)/include
OPENSSL_LIBS=-L$(OPENSSL_DIR) -L./ -lssleay32  -leay32 
#-lssleay32  -leay32 
OPENSSL_LDFLAGS= $(OPENSSL_LIBS)

LIB_MODULE_SOURCES=testcallback.cpp
LIB_MODULE_OBJS=testcallback.o
LIB_NAME=libtestcallback
LIB_MODULE_CFLAGS=$(CFLAGS) $(OPENSSL_INCLUDES) $(SYS_CFLAGS) -fPIC 
LIB_MODULE_LDFLAGS=-shared  -g $(OPENSSL_LDFLAGS) -lwsock32 -lstdc++ 
LIB_MODULE_STATIC_LDFLAGS=  -g $(OPENSSL_LDFLAGS) -lwsock32 -lstdc++ 
	
DEF_LIB_FLAG=-Wl,--output-def,$(LIB_NAME).def,--out-implib,$(LIB_NAME).lib 
DEF_LIB_FLAG_NATIVE=-Wl,--output-def,native_tassl_sock_wrap.def,--out-implib,native_tassl_sock_wrap.lib \

	
	
$(LIB_NAME).dll: $(LIB_MODULE_SOURCES)
	@echo "-->Build callback lib"
	$(CC) $(LIB_MODULE_CFLAGS) -c testcallback.cpp
	$(CC) $(LIB_MODULE_OBJS)  $(LIB_MODULE_LDFLAGS) $(DEF_LIB_FLAG)  -o $(LIB_NAME).dll


testcb: testcallback.cpp
	@echo "-->Build test_native"
	$(CC) $(LIB_MODULE_CFLAGS)  -D__RUN_MAIN__  -c testcallback.cpp
	$(CC)  -D__RUN_MAIN__  testcallback.o -lstdc++ -o testcb
		

clean:
	-@rm -f $(LIB_MODULE_OBJS)
	-@rm -f $(LIB_NAME).dll
	-@rm -f testcb.exe
	-@rm -f *.def
	-@rm -f *.lib
	-@rm -f *.o
